<template>
  <el-dialog title="断面基础信息录入" :visible.sync="dialogVisible" width="40%" :before-close="handleClose">
    <el-form :model="scetion" label-width="100px" class="demo-form-inline">
      <el-row>
        <el-col :span="12">
          <el-form-item label="开挖方式">
            <el-select v-model="scetion.eId" placeholder="请选择">
              <el-option
                command="e"
                v-for="v in etypeList"
                :label="v.eName"
                :key="v.eId"
                :value="v.eId"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="断面名称">
            <el-input v-model="scetion.sectionName"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="围岩级别">
            <el-select v-model="scetion.wallgrade" placeholder="请选择围岩级别">
              <el-option label="Ⅱ" value="2"></el-option>
              <el-option label="Ⅲ" value="3"></el-option>
              <el-option label="Ⅳ" value="4"></el-option>
              <el-option label="Ⅴ" value="5"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="布设时间">
            <el-date-picker
              type="date"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择日期"
              v-model="scetion.createTime"
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="create">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import api from "../../../api";
import qs from "qs";
export default {
  data() {
    return {
      dialogVisible: false,
      //项目信息
      tunnelList: [],
      etypeList: [],
      scetion: {
        wId: "",
        eName: "",
        eId: "",
        sectionName: "",
        createTime: "",
        wallgrade: "",
      },
    };
  },
  mounted() {
    this.$bus.$on("onAddSection", (flag) => {
      if (this.scetion.wId == "") {
        this.$message({
          type: "fail",
          message: "请选择洞幅",
        });
        this.dialogVisible = false;
      } else {
        this.dialogVisible = true;
      }
    });
    this.$bus.$on("onAddSectionWid", (flag) => {
      this.scetion.wId = flag;
    });
    // 查询隧道
    this.kaiwa();
  },
  methods: {
    kaiwa() {
      api
        .eTypeFindByAll()
        .then((res) => {
          if (res.data.code == 2001) {
            this.etypeList = res.data.data;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
    create() {
      if (this.scetion.wId == "") {
        this.$message({
          type: "fail",
          message: "请选择洞幅",
        });
        return;
      }
      api
        .tunnelSectionsave(qs.stringify(this.scetion))
        .then((res) => {
          if (res.data.code == 2001) {
            this.$message({
              type: "success",
              message: "添加成功!",
            });
            this.dialogVisible = false;
            this.$bus.$emit("onRefreshSection", this.scetion.wId);
          } else {
            this.$message({
              type: "fail",
              message: res.data.message,
            });
          }
        })
        .catch((err) => {});
    },
  },
};
</script>

<style scoped>



</style>